package com.i3nu.blog.dialog;


import com.i3nu.contacts.activity.R;

import android.app.Dialog;
import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;

public class UpdateDialog extends Dialog{
	/** Update Message Text */
	private TextView uploadMessageText;
	
	/** Update Image Path Text */
	private TextView uploadImagePathText;
	
	/** Update Text */
	private EditText updateText;
	
	/** Counter */
	private TextView counterText;
	
	/** Max Text */
	private final int MAX_TEXT_COUNT = 140;
	/** MODE NEW TWEET */
	public static final int MODE_NEW_TWEET = 1;
	
	/** MODE AT MESSAGE */
	public static final int MODE_AT_MESSAGE = 2;

	/** Upload Image Button */
	private ImageButton uploadImageButton;
	
	/** OK Button */
	private Button okButton;
	
	/** Cancel Button */
	private Button cancelButton;

	public UpdateDialog(Context context, int mode) {
		super(context);
		super.setContentView(R.layout.dialog_update);
		
		//Upload Image Text
		uploadMessageText = (TextView)findViewById(R.id.upload_message);
		//Upload Image Path Text
		uploadImagePathText = (TextView)findViewById(R.id.file_path);
		
		//Update Text
		updateText = (EditText)findViewById(R.id.update_text);
		//Counter
		counterText = (TextView)findViewById(R.id.counterText);
		counterText.setText(String.valueOf(MAX_TEXT_COUNT));
		
		//Upload Image Button
		uploadImageButton = (ImageButton)findViewById(R.id.uploadImageButton);		
		uploadImageButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//Open Dialog
				/*FileExplorer dialog = new FileExplorer(getContext());
				dialog.setTarget(uploadImagePathText);
				dialog.show();*/
				Log.v("blog", "open file explore");
			}
		});
		
		updateText.addTextChangedListener(new TextWatcher() {			
			@Override
			public void onTextChanged(CharSequence s, int start, int before, int count) {
				int leftCount;
				leftCount = MAX_TEXT_COUNT - updateText.getText().toString().length();
				Log.v("blog","updateText changing...");
				counterText.setText(String.valueOf(leftCount));
						
				if(leftCount < 0){
					counterText.setTextColor(0xFFFF4500);
					okButton.setVisibility(android.view.View.INVISIBLE);
				}else{
					okButton.setVisibility(android.view.View.VISIBLE);
					counterText.setTextColor(0xFFF5FFFA);
				}
			}
			
			@Override
			public void beforeTextChanged(CharSequence s, int start, int count,
					int after) {			
			}
			
			@Override
			public void afterTextChanged(Editable s) {
			}
		});
		//OK Button
		okButton = (Button)findViewById(R.id.okButton);
		okButton.setText(android.R.string.ok);
		okButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {	
//					updateMessage();
				Log.v("blog", "update...");
			}
		});
		
		//Cancel Button
		cancelButton = (Button)findViewById(R.id.cancelButton);
		cancelButton.setText(android.R.string.cancel);
		cancelButton.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
//				dismiss();
				Log.v("blog", "cancel button clicked");
			}
	});
	}

}
